﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DynamicQuery.Mvc;
using DynamicQuery.SampleData;
using System.Data;
using DynamicQuery;


namespace DynamicQuery.SampleWeb.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index(QueryDescriptor descriptor)
        {
            ShopContainer ctx = new ShopContainer();
            var result = ctx.Products.Query(descriptor);
            return View("Product",result);
        }

        public ActionResult Product(QueryDescriptor descriptor)
        {
            descriptor.PageSize = 5;
            descriptor.OrderBy = new OrderByClause { Key = "Id", Order = OrderSequence.ASC };

            ShopContainer ctx = new ShopContainer();
            int pageCount;
            var result = ctx.Products.Query(descriptor, out pageCount);
            Pager pager = new Pager(pageCount, descriptor);
            ViewBag.Pager = pager;
            return View("Index",result);
        }

    }
}
